%DASOV24daily.m

% Daily gold prices and 10-year tips yields -- 2003 onward

clear

% Use Xau, Xag and Xpt for intraday time alignment
X =          xlsread('GoldBBXAU.xlsx',1,'B9:B5576');
[~, timlab]= xlsread('GoldBBXAU.xlsx',1,'A9:A5576');
XGoldXau = flip([ datenum(timlab,'mm/dd/yyyy') X]); 

X =          xlsread('SilverBBXAG.xlsx',1,'B9:B5576');
[~, timlab]= xlsread('SilverBBXAG.xlsx',1,'A9:A5576');
XSilvXag = flip([ datenum(timlab,'mm/dd/yyyy') X]); 

X =          xlsread('PlatinumBBXPT.xlsx',1,'B9:B5576');
[~, timlab]= xlsread('PlatinumBBXPT.xlsx',1,'A9:A5576');
XPlatXpt = flip([ datenum(timlab,'mm/dd/yyyy') X]); 

X =          xlsread('TIPS10BB.xlsx',1,'B7:B5360');
[~, timlab]= xlsread('TIPS10BB.xlsx',1,'A7:A5360');
XY10 = flip([ datenum(timlab,'mm/dd/yyyy') X]); 

% Regressions of log price change on log yield change conditional on low/high yields

% Line up daily data
[commonDates, ind1, ind2] = intersect(XGoldXau(:,1), XY10(:,1));
XGoldall = [commonDates, XGoldXau(ind1,2), XY10(ind2,2)];

[commonDates, ind1, ind2] = intersect(XSilvXag(:,1), XY10(:,1));
XSilvall = [commonDates, XSilvXag(ind1,2), XY10(ind2,2)];

[commonDates, ind1, ind2] = intersect(XPlatXpt(:,1), XY10(:,1));
XPlatall = [commonDates, XPlatXpt(ind1,2), XY10(ind2,2)];

% Select dates for sample
% from  datenum(2003,1,2) to datenum(2024,5,21)

sambeg = datenum(2003,1,2);
samend = datenum(2024,5,21);

% Run regressions for Gold, Silver and Platinum
pric  =  XGoldall(:,2);
dpric =  XGoldall(:,1);
yiel  =  XGoldall(:,3);
dyiel =  XGoldall(:,1);
[TGold2, TP5slopG, P5sigG, P5rsqG, Coeff_PvalG]= Runregsdailyf(pric,yiel,dpric,dyiel,sambeg,samend);

pric  =  XSilvall(:,2);
dpric =  XSilvall(:,1);
yiel  =  XSilvall(:,3);
dyiel =  XSilvall(:,1);
[TSilv2, TP5slopS, P5sigS, P5rsqS, Coeff_PvalS]= Runregsdailyf(pric,yiel,dpric,dyiel,sambeg,samend);

pric  =  XPlatall(:,2);
dpric =  XPlatall(:,1);
yiel  =  XPlatall(:,3);
dyiel =  XPlatall(:,1);
[TPlat2, TP5slopP, P5sigP, P5rsqP, Coeff_PvalP]= Runregsdailyf(pric,yiel,dpric,dyiel,sambeg,samend);

% 5 equally sized portfolio low to high yield
TAB5 = table(TP5slopG, P5sigG', P5rsqG,TP5slopS, P5sigS', P5rsqS,TP5slopP, P5sigP', P5rsqP)



